package com.li.algorithm.leetcode.hot100;

public class Test5 {

    public int maxArea(int[] height) {
        int i = 0, j = height.length - 1;
        int max = -1;
        //area = (j-i) * min(height[i], height[j])
        while (i < j) {
            int area = (j-i) * Math.min(height[i], height[j]);
            max = Math.max(max, area);
            if (height[i] >= height[j]) {
                j--;
            } else if (height[j] > height[i]) {
                i++;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        Test5 t = new Test5();
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(t.maxArea(height));

    }
}
